﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using System.Drawing;

public partial class Interviewer_ModifyTimeInterview : System.Web.UI.Page
{

    string sqlconn = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        sqlconn = WebConfigurationManager.ConnectionStrings["connection"].ToString();
        if (!IsPostBack)
        {
            BindInterview();
        }
    }

    protected void BindInterview()
    {
        SqlConnection conn = new SqlConnection(sqlconn);
        SqlCommand cmd = new SqlCommand("Select * from tb_Interview", conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        conn.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvInterview.DataSource = ds;
            gvInterview.DataBind();
        }
        else
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            gvInterview.DataSource = ds;
            gvInterview.DataBind();
            int columncount = gvInterview.Rows[0].Cells.Count;
            gvInterview.Rows[0].Cells.Clear();
            gvInterview.Rows[0].Cells.Add(new TableCell());
            gvInterview.Rows[0].Cells[0].ColumnSpan = columncount;
            gvInterview.Rows[0].Cells[0].Text = "No Records Found";
        }

    }


    protected void gvInterview_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvInterview.EditIndex = -1;
        BindInterview();
    }
    protected void gvInterview_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvInterview.EditIndex = e.NewEditIndex;
        BindInterview();
    }
    protected void gvInterview_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlConnection conn = new SqlConnection(sqlconn);
        int id = Convert.ToInt32(gvInterview.DataKeys[e.RowIndex].Value.ToString());
        string InterviewerID = gvInterview.DataKeys[e.RowIndex].Values["InterviewerID"].ToString();
        string VacancyID = gvInterview.DataKeys[e.RowIndex].Values["VacancyID"].ToString();
        string ApplicantID = gvInterview.DataKeys[e.RowIndex].Values["ApplicantID"].ToString();



        TextBox txtDateInterview = (TextBox)gvInterview.Rows[e.RowIndex].FindControl("txtDateInterview");
        TextBox txtTimeDetails = (TextBox)gvInterview.Rows[e.RowIndex].FindControl("txtTimeDetails");

        conn.Open();
        SqlCommand cmd = new SqlCommand("update tb_Interview set DateInterview='" + txtDateInterview.Text + "',TimeDetails='" + txtTimeDetails.Text + "' where InterviewID=" + id, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        Label1.ForeColor = Color.Green;
        Label1.Text = "Modify successfully";
        gvInterview.EditIndex = -1;
        BindInterview();
    }


    protected void gvInterview_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }
    protected void gvInterview_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void gvInterview_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvInterview.PageIndex = e.NewPageIndex;
        BindInterview();
    }
    


}